Page({
  data: {
    recordList: [],
    isIPhoneX: false,
  },
  onLoad() {
    this.isIphoneX()
  },
  onShow() {
    this.getRecordList()
  },
  isIphoneX() {
    let res = wx.getSystemInfoSync();
    if (res.screenHeight === 812 || res.screenHeight === 896) {
      this.setData({
        isIPhoneX: true
      })
    } else {
      this.setData({
        isIPhoneX: false
      })
    }
  },
  getRecordList() {
    const that = this
    const userID = wx.getStorageSync('userID')
    wx.cloud.database().collection('information')
      .where({
        userID
      }).orderBy("createdAt", "desc")
      .get()
      .then(res => {
        if (res.data && res.data.length > 0) {
          that.setData({
            recordList: res.data,
          })
        }
      }).catch(err => {
        wx.showToast({
          title: err,
          icon: 'error',
          duration: 2000
        })
      })
  },
  handleEdit(e) {
    const record = e.target.dataset.record;

    wx.navigateTo({
      url: `/pages/update/index?batteryId=${record._id}`,
    })
  }
})